package com.cloud.mall.oms.service.impl;

import com.cloud.mall.base.BaseResponse;
import com.cloud.mall.core.bean.MallBeanUtils;
import com.cloud.mall.oms.input.OmsOrderSettingInpDTO;
import com.cloud.mall.oms.mapper.OmsOrderSettingMapper;
import com.cloud.mall.oms.model.OmsOrderSetting;
import com.cloud.mall.oms.out.OmsOrderSettingOut;
import com.cloud.mall.oms.service.OmsOrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OmsOrderSettingServiceImpl implements OmsOrderSettingService {
    @Autowired
    private OmsOrderSettingMapper orderSettingMapper;

    @Override
    public BaseResponse update(Long id,@RequestBody OmsOrderSettingInpDTO omsOrderSettingInpDTO) {
        OmsOrderSetting orderSetting=MallBeanUtils.dtoToDo(omsOrderSettingInpDTO,OmsOrderSetting.class);
        orderSetting.setId(id);
        int count= orderSettingMapper.updateByPrimaryKey(orderSetting);
        if (count==0){
            return  BaseResponse.setResultError();
        }
        return  BaseResponse.setResultSuccess(count);
    }

    @Override
    public BaseResponse<OmsOrderSettingOut> getItem(Long id, OmsOrderSettingOut omsOrderSettingOut) {
        return BaseResponse.setResultSuccess(MallBeanUtils.dtoToDo(orderSettingMapper.selectByPrimaryKey(id),OmsOrderSettingOut.class));
    }
}
